<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/sm.css"/>

    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .title_p {
            height: 35px;
            line-height: 41px;
            color: #333;
            font-size: 12px;
            padding: 0 15px;
        }
        .main {
            background-color: #fff;
        }
        .li_box {
            height: 50px;
            line-height: 50px;
            border-bottom: 1px solid #e8e8e8;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            padding: 0 15px;
        }
        .main ul li:last-child .li_box {
            border-bottom: none;
        }
        .box_s {
            background-color: #fff;
            border-bottom: none;
            margin-bottom: 6px;
        }
        .box_s .li_boxr {
            font-size: 18px;
        }
        .li_boxl {
            width: 0;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            padding-right: 10px;
            color: #333;
            font-size: 15px;
        }
        .li_boxr {
            font-size: 12px;
            color: #999;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .active {
            color: #e62442;
            font-size: 16px;
        }
        .picker-calendar-row:nth-child(6){
            display: none;
        }
        .picker-calendar-months-wrapper{
            height: 194px;
        }

    </style>
</head>
<body>
    <div class="li_box box_s">
        <div class="li_boxl">待结算收入</div>
        <div class="li_boxr active">RM<span class="balance"></span></div>
    </div>
    <div class="calendar">
        <div class="page-group">
            <div class="page">
                <div class="content">
                    <div class="content-block">
                        <div class="list-block">
                            <div data-toggle="date" id='calendar-inline'></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="title_p"></div>
    <div class="main">
        <ul>
            <li>
                <div class="li_box">
                    <div class="li_boxl">订单数</div>
                    <div class="li_boxr order_num"></div>
                </div>
            </li>
            <li>
                <div class="li_box">
                    <div class="li_boxl">总计</div>
                    <div class="li_boxr active">RM <span class="total_money"></span></div>
                </div>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/sm.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    var dateTime = new Date();
    var selectDate = dateTime.getFullYear() + '-' + add0(parseInt(dateTime.getMonth() + 1)) + '-' + add0(dateTime.getDate()); // 默认时间
        // 日历
    apiready = function(){
        
        // 下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            reloadData();
            api.refreshHeaderLoadDone();
        });

        api.addEventListener({
            name: 'loginEvent'
        }, function(ret, err) {
            if (ret) {
                reloadData();
            }
        });

        reloadData();
    };

    function reloadData () {
        $("#calendar-inline").html('');
        selectDate = dateTime.getFullYear() + '-' + add0(parseInt(dateTime.getMonth() + 1)) + '-' + add0(dateTime.getDate()); // 默认时间
        $("#calendar-inline").calendar({
            onChange: function() {
                // console.log($('.picker-calendar-day-selected').attr('data-date'));
                var originalDate = $('.picker-calendar-day-selected').attr('data-date'); 
                selectDate = changeMonthFormat(originalDate);
                getIncome(selectDate);
            },
            onOpen: function(){
                $(".picker-calendar-day-today").addClass('picker-calendar-day-selected');
                getIncome(selectDate);
            }
        });
    };

    // 根据日期获取收入详情
    function getIncome (_date) {
        shop = $api.getStorage('shop_data');
        openLoading();
        $(".title_p").html(fomateDate(_date));
        api.ajax({
            url: rootPath + '/api/seller/get_seller_income',
            method: 'post',
            data: {
                values: { 
                    shop_id: shop.id,
                    token: shop.token,
                    date: _date
                },
            }
        }, function(ret, err) {
            if (ret.status == 200) {
                var _total_money = parseFloat(ret.data.total_income).toFixed(2);
                var _order_num = ret.data.total_num;
                var balance = parseFloat(ret.data.balance).toFixed(2);
            } else {
                var _total_money = 0.00;
                var _order_num = 0;
                var balance = 0.00;
            }
            $('.balance').text(balance);
            $(".total_money").html(_total_money);
            $(".order_num").html(_order_num);
            closeLoading();
        });
    };

    function add0(m){return m<10?'0'+m:m }
    
    /*var a =  '2017-03-14';
    changeMonthFormat(a);*/
    // 传入的_date为 '2017-03-14'
    function changeMonthFormat (_date) {
        var _m = _date.split('-');
        var m = add0(parseInt(_m[1]) + 1);
        var final = _m[0] + '-' + m + '-' + add0(_m[2]);
        return final;
    };

    function fomateDate (_date) {
        var _m = _date.split('-');
        return _m[1] + '月' + _m[2] + '日';
    };
</script>
</html>